package com.example.attack.controller;

import com.example.attack.model.ElCharacter;
import com.example.attack.service.ElCharacterService;
import com.example.attack.service.TransactionService;
import com.example.attack.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mp")
public class MybatisController {

    @Autowired
    private ElCharacterService elCharacterService;
    @Autowired
    private TransactionService transactionService;

    @GetMapping("/mockSelectDelayCommon")
    public R mockSelectDelayCommon(@RequestParam("id")Integer id) throws InterruptedException {
        elCharacterService.mockSelectDelayCommon(id);
        return R.success("成功");
    }

    @GetMapping("/mockSelectDelayTranscational")
    public R mockSelectDelayTransactional(@RequestParam("id")Integer id) throws InterruptedException {
        elCharacterService.mockSelectDelayTransactional(id);
        return R.success("成功");
    }

    @GetMapping("/update")
    public R update(@RequestParam("id")Integer id){
        elCharacterService.updateElCharacter(id);
        return R.success("更新成功");
    }

    @GetMapping("/independentTransaction")
    public R independentTransaction(){
        transactionService.forIndependentTransaction();
        return R.success("测试");
    }
}
